package com.googlecode.scup.parser;

import com.googlecode.scup.grammar.grammarspart.Symbol;
import com.googlecode.scup.parser.actionstates.ActionState;
import com.googlecode.scup.parser.automat.Automat;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ActionTable {
    private Automat automat = null;
    private List<Map<Symbol,  Integer>> table = null;
    private List<Map<Symbol, ActionState>> states = null;

    public ActionTable(Automat automat) {
        this.automat = automat;
        states = new ArrayList<Map<Symbol, ActionState>>();
        states = this.automat.getShift(states);
        states = this.automat.getGoto(states);
        states = this.automat.getReduce(states);
        states = this.automat.getAccept(states);
    }

    public static List<Map<Symbol, ActionState>> createActionTable(Automat automat) {
        List<Map<Symbol, ActionState>> result = new ArrayList<Map<Symbol, ActionState>>();
        result = automat.getShift(result);
        result = automat.getReduce(result);
        result = automat.getAccept(result);
        return result;
    }

    public static List<Map<Symbol, ActionState>> createGotoTable(Automat automat) {
        List<Map<Symbol, ActionState>> result = new ArrayList<Map<Symbol, ActionState>>();
        result = automat.getGoto(result);
        return result;
    }

    public String forTest() {
        StringBuilder result = new StringBuilder();
        for (Map map : states) {
            result.append('\n');
            result.append(map);
        }
        return result.toString();
    }
}
